package com.feisuanyz.repository;

import com.feisuanyz.entity.UserPermission;
import com.feisuanyz.entity.UserPermissionDO;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *   用户权限表的持久化接口
 * </p>
 * @author 23265
 */
@Repository
public interface UserPermissionRepository extends JpaRepository<UserPermission, Integer> {

    boolean existsByUserIdAndPermissionLevel(Integer userId, String permissionLevel);

    @Query("SELECT up FROM UserPermission up WHERE up.userId = :userId AND up.permissionLevel IN (:permissionLevels)")
    List<UserPermission> findByUserIdAndPermissionLevels(Integer userId, List<String> permissionLevels);

    Optional<UserPermissionDO> findByUserIdAndPermissionLevel(Integer userId, String permissionLevel);

    // 合并需并入的代码中的独有方法
    UserPermissionDO findByUserIdAndEventId(Integer userId, Integer eventId);
}